<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    
        var x = 5;
        a();   //undefined
        function a() {
            alert(x);
            var x = 10;
        }
        alert(x);   //5

        /*
        1.定义
            var x;
            function a() {......}

        2.执行
            x = 5;
            a();  ==>  新的作用域
                        1.定义
                            var x;
                        2.执行
                            alert(x);  //undefined
                            x = 10;

            alert(x);  //5
        */

    </script>
</body>
</html>